<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="net.sf.jasperreports.engine.JasperPrint"%>
<%@page import="edu.ccut.saturn.tag.report.servlet.IReport"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
<%
			JasperPrint print = (JasperPrint) session
			.getAttribute(IReport.PRINT);

	String pageIndexStr = request.getParameter(IReport.HTML_PAGE_INDEX);

	if (pageIndexStr == null || "".equals(pageIndexStr.trim())) {
		pageIndexStr = "0";
	}

	int pageSize = print.getPages().size();
	int pageIndex = Integer.parseInt(pageIndexStr);

	out.print("打印预览页  第" + (pageIndex + 1) + "页 共" + pageSize + "页");
	if (session.getAttribute("direction") == null) {
		session.setAttribute("direction", "01");
	}
	if (session.getAttribute("format") == null) {
		session.setAttribute("format", "A4");
	}
%>
</title>
<script>
function print(){
	printapplet.print();
}
function first(){
	window.open("<%=request.getContextPath()%>/do.report?reload=true&pageIndex=0&reportType=html&topmargin="+aa+"&leftmargin="+bb, "_self")
}
function getDirection(){
	if("<%=session.getAttribute("direction")%>"!=null){
		return "<%=session.getAttribute("direction")%>";
	}else{
		var direction = "";
		var dOb = pageSize.direction;
		for(var i=0;i<dOb.length;i++){
			if(dOb[i].checked){
				direction=dOb[i].value;
			}
		}
		return direction;
	}
}
function getFormat(){
	if("<%=session.getAttribute("format")%>"!=null){
		return "<%=session.getAttribute("format")%>";
	}else{
		var format = pageSize.format.value;
		return format;
	}
}
function next(){
	window.open("<%=request.getContextPath()%>/do.report?reload=true&pageIndex=<%=pageIndex + 1%>&reportType=html&direction="+getDirection()+"&format="+getFormat(),"_self")
}
function last(){
	window.open("<%=request.getContextPath()%>/do.report?reload=true&pageIndex=<%=pageSize - 1%>&reportType=html&direction="+getDirection()+"&format="+getFormat(),"_self")
}
function previous(){
	window.open("<%=request.getContextPath()%>/do.report?reload=true&pageIndex=<%=pageIndex - 1%>&reportType=html&direction="+getDirection()+"&format="+getFormat(),"_self")
}
function reload()
{
window.open("<%=request.getContextPath()%>/do.report?reload=true&reportType=html&direction="+getDirection()+"&format="+getFormat(),"_self")
}

function pageSizeFunc(){
	pageSize.submit();
}
function printFormatFunc(){
	var dOb = pageSize.direction;
	for(var i=0;i<dOb.length;i++){
		if(dOb[i].checked){
			printFormat.direction.value=dOb[i].value;
		}
	}
	printFormat.format.value=pageSize.format.value;
	printFormat.submit();
}
</script>
<style type="text/css">
select {
	width: 50px;
}

.handler {
	width: 538px;
	text-align: right;
	background: silver;
}

button {
	margin: 0 auto;
	height: 23px;
	background-image: url(/report/img/bt_bg.jpg);
	line-height: 23px;
	text-align: center;
	cursor: pointer;
	border: #82D9F2 solid 1px;
	color: #0A7CB7;
}

.button {
	margin: 0 auto;
	height: 23px;
	background-image: url(/report/img/bt_bg.jpg);
	line-height: 23px;
	text-align: center;
	cursor: pointer;
	border: #82D9F2 solid 1px;
	color: #0A7CB7;
}

.main {
	text-align: center;
	width: 100%;
}

s
body {
	font-size: 12px;
	margin: 0 auto;
	padding: 0px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	width: 1002px;
}
</style>
</head>
<body
	style="position: relative; padding: 0px; margin: 0px; text-align: center; background: #ccc; font-size: 12px;">
<div
	style="background: url(/server-main/img/div_bg.jpg) repeat-x 0 0; height: 50px; line-height: 50px; font-size: 12px; color: #666; width: 100%">
<div style="width: 750px; margin: 0 auto;">
<form method="post" target="_self"
	action="<%=request.getContextPath()%>/do.report" name="pageSize"
	style="display: block; float: left; margin: 0 5px; padding: 0px; width: 250px; background: url(/server-main/img/f_b.gif) no-repeat 200px 15px;">
<input type="hidden" name="reload" value="true" /> <select
	style="float: left; display: block; margin: 11px 5px 0 5px;"
	name="format">
	<option value="A1">A1</option>
	<option value="A2">A2</option>
	<option value="A3">A3</option>
	<option value="A4" selected="selected">A4</option>
	<option value="A5">A5</option>
	<!-- <option value="A6">A6</option>
	<option value="A7">A7</option>
	<option value="A8">A8</option>
	<option value="A9">A9</option> -->
</select> <input type="radio" name="direction" value="01" checked="checked"
	style="float: left; display: block; margin: 14px 0 0;" /><label
	style="float: left; display: block;">纵向</label> <input type="radio"
	name="direction" value="portait"
	style="float: left; display: block; margin: 14px 0 0;" /><label
	style="float: left; display: block;">横向</label> <a
	href="javascript:pageSizeFunc()"
	style="background: url(/server-main/img/bt_bt_1.gif) no-repeat center 12px; height: 48px; width: 50px; border: none; cursor: pointer; display: block; float: left;"
	title="刷新"></a></form>

<form
	style="display: block; float: left; margin: 0 5px; padding: 0px; width: 250px; background: url(/server-main/img/f_b.gif) no-repeat 200px 15px;"
	method="post" target="_blank"
	action="<%=request.getContextPath()%>/do.report" name="printFormat">
<input type="hidden" name="reload" value="true" /> <input type="hidden"
	name="format" /><input type="hidden" name="direction" /><select
	style="float: left; display: block; margin: 11px 0 0;"
	name="reportType">
	<option value="pdf">pdf</option>
	<option value="excel">excel</option>
	<!-- <option value="word"></option> -->
	<option value="xml">word</option>
	<!-- <option value="csv">csv</option>-->
	<option value="rtf">xml</option>
	<!-- <option value="print">print</option> -->
</select> <a href="javascript:printFormatFunc()"
	style="background: url(/server-main/img/bt_bt_2.gif) no-repeat center 10px; height: 48px; cursor: pointer; width: 50px; display: block; float: left;"
	title="导出"></a></form>
<a
	style="background: url(/server-main/img/bt_3.gif) no-repeat center 8px; height: 48px; width: 50px; cursor: pointer; margin: 0 5px; display: block; float: left;"
	title="打印"></a> <%
 if (0 == pageIndex) {
 %> <a title="上一页"
	style="float: left; display: block; height: 50px; color: #999999; text-decoration: none; padding: 0 20px; background: url(/server-main/img/j_1.gif) no-repeat 5px 18px; cursor: default;">上一页</a>

<%
} else {
%> <a title="上一页" href="javascript:previous()"
	style="float: left; display: block; height: 50px; color: #999999; text-decoration: none; padding: 0 20px; background: url(/server-main/img/j_1.gif) no-repeat 5px 18px;">上一页</a>

<%
}
%> <%
 if ((pageIndex + 1) == pageSize) {
 %> <a title="下一页"
	style="float: left; display: block; height: 50px; color: #999999; text-decoration: none; padding: 0 20px; background: url(/server-main/img/j_2.gif) no-repeat 60px 18px; cursor: default;">下一页</a>

<%
} else {
%> <a title="下一页" href="javascript:next()"
	style="float: left; display: block; height: 50px; color: #999999; text-decoration: none; padding: 0 20px; background: url(/server-main/img/j_2.gif) no-repeat 60px 18px;">下一页</a>

<%
}
%>
</div>
</div>
<div style="background: #ccc; min-width: 200px;">
<div style="border-top: #999 solid 1px; margin: 2px; height: 15px;"></div>
<div style="line-height: 22px; padding: 0px; height: 15px;"><%=request.getAttribute(IReport.HTML_OUT_BUFFER).toString()%></div>
<p id="ppage"
	style="background-color: #fff; margin: 0px; padding: 0px; display: block; height: 25px; line-height: 25px; text-align: center; color: #666;"><span
	style="float: center;">第<%=pageIndex + 1%>/<%=pageSize%>页</span></p>
</div>
<br />
<br />
<br />
<br />
<script type="text/javascript">
var formats = "A4";
var direction;
if("<%=session.getAttribute("direction")%>"=="01"){
	direction = "01"; 
	pageSize.direction[0].checked="checked";
}else {
	direction = "portait";
	pageSize.direction[1].checked="checked";
}if("<%=session.getAttribute("format")%>"=="A4"){
	formats = "A4";
	pageSize.format[3].selected = "selected";
}else{
	for(var i=0;i<pageSize.format.length;i++){
		if("<%=session.getAttribute("format")%>"==pageSize.format[i].value){
			formats = "<%=session.getAttribute("format")%>";
			pageSize.format[i].selected = "selected";
		}
	}
}
var formatToWidth = {A1:"1684",A2:"1190",A3:"842",A4:"595",A5:"421"};
var formatToHeight = {A1:"2380",A2:"1684",A3:"1190",A4:"842",A5:"595"};
if(direction=="01"){
	ppage.style.width=eval("formatToWidth." + formats);
}else{
	ppage.style.width=eval("formatToHeight." + formats);
}

</script>
</body>
</html>
